package core;

import graphic.Print;

import java.util.ArrayList;
import jbook.util.*;

public class Administrator {
	private static final int MIN_MOBS = 2;
	private static final int MIN_POTIONS = 2;
	private static final int TURNS = 3;
	private static int time = 0;
	private static Player player;
	private static Prison prison = new Prison();
	private static ArrayList<Monster> monsters = new ArrayList<Monster>();
	private static final Print i = new Print();
	private static ArrayList<Monster> deleteMonsters;

	public static void main(String[] args) {
		/* Place the player at the entrance */
		player = new Player(prison.getRoom());

		/* Create mobs and place them */
		for (int i = 0; i < MIN_MOBS; i++) {
			monsters.add(new Monster(prison.getRoom()));
		}

		/* Create potions and place them */
		for (int i = 0; i < MIN_POTIONS; i++) {
			new Potion(prison.getRoom());
		}

		while (player.getHp() != 0
				&& player.getPos() != prison.getRoom().getExit().getPos()) {

			// TODO ask the player to do something
			do {
				i.printRoom(prison.getRoom());
				i.printStatus(player);
				System.out.printf("\n Where do you want to move? ");
			} while ((!player.move(Input.readChar(), prison.getRoom())));

			deleteMonsters = new ArrayList<Monster>();
			/* Need to check if mob died */
			for (Monster m : monsters)
				if (m.getHp() == 0)
					deleteMonsters.add(m);
			for (Monster m : deleteMonsters)
				monsters.remove(m);

			/* Move each monster */
			for (Monster m : monsters)
				m.selfMovement(prison.getRoom());

			/* The player levels up every TURNS turns */
			if (++time % TURNS == 0)
				player.levelUp();

			deleteMonsters = new ArrayList<Monster>();
			/*
			 * Every turn need to check if any monster died, and if so, remove
			 * it
			 */
			for (Monster m : monsters)
				if (m.getHp() == 0)
					deleteMonsters.add(m);
			for (Monster m : deleteMonsters)
				monsters.remove(m);

		}

		if (player.getHp() == 0)
			System.out.printf("You lost sorry\n");
		// TODO you lost sorry
		else
			System.out.printf("Cool, you WON!!!\n");
		// TODO you won
	}
}
